<?php 
namespace XFCore\controllers\admin;
use lib\BaseController;
use lib\Commontc;
class IndexController extends BaseController{
    
    public function __construct(){
       parent::__construct();
    }
    public function index(){
         if($this->islogin_admin != 1)Commontc::falsetc("请先登录",rethreffun('/login',false));
         include admintem.'index.php';
    }
    public function login($get){
        if(isset($get['logout'])){
        	setcookie("admin_token", "", time() - 99999999999999999 , '/');
        	@header('Content-Type: text/html; charset=UTF-8');
        	Commontc::truetc("注销成功！",rethreffun('/login'));
        }
        if($this->islogin_admin == 1)Commontc::truetc("您已登录！",rethreffun('/index'));
        include admintem.'login.php';
    }
    public function main(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'main.php';
    }
    public function site($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        if ($get['my'] == "upLoad") {
            
            if (copy($_FILES['file']['tmp_name'], PUBLICROOT . '/assets/img/logo.png')) {
                exitjson(200,'上传成功');
            } else {
                exitjson(500,'上传Logo失败');
            }
        }
        include admintem.'site.php';
    }
    public function template($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        
        if($get['my'] == 'getListData'){
            
             header("Content-Type: application/json");
            $mblist = \lib\Template::getList();
            $data = [];
            foreach ($mblist as $k => $v) {
                $data[] = ["id" => ($k + 1), "title" => $v, "image" => "\../template/" . $v . "/preview.png", "remark" => "", "time" => "V9.9.9"];
            }
            exit(json_encode(['msg' => "not data","count" => count($mblist), "data" => $data, "code" => 0, ], 320));
        }
        include admintem.'template.php';
    }
    public function pay(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'pay.php';
    }
    public function pay_meal(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $meals = $this->conf->pay_meal;
        if (!is_array($meals)) $meals = [];
        include admintem.'pay_meal.php';
    }
    public function SetNotice(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'SetNotice.php';
    }
    public function mail(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'mail.php';
    }
    public function logintemplate($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        if($get['my'] == 'getListData'){
             header("Content-Type: application/json");
            $mblist = \lib\LoginTemplate::getList();
            $data = [];
            foreach ($mblist as $k => $v) {
                $data[] = ["id" => ($k + 1), "title" => $v, "image" => "\../ltemplate/" . $v . "/preview.png", "remark" => "", "time" => "V9.9.9"];
            }
            exit(json_encode(['msg' => "not data","count" => count($mblist), "data" => $data, "code" => 0, ], 320));
        }
        include admintem.'logintemplate.php';
    }
    public function Order(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'Order.php';
    }
    public function consume(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'consume.php'; 
    }
    public function User($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my'] ?? "list";
        $id = $get['id'];
        if(!empty($id) && $my == 'edit'){
            $row = $this->db->userrow($id,'pid');
        }
        include admintem.'User.php';
    }
    public function Qrlist(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'Qrlist.php';
    }
    public function Package($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my'] ?:'list';
        $id = $get['id'] ?:"";
        if($my == 'edit' && !empty($id)){
            $row = $this->db->packagerow($id);
        }
        include admintem.'Package.php';
    }
    public function pay_vip(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'pay_vip.php';
    }
    public function Wechat_Trumpet($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my']?:'list';
        $id = $get['id'];
        if(!empty($id) && $my == 'edit'){
            $row = $this->db->wechat_trumpetrow($id);
        }
        include admintem.'Wechat_Trumpet.php';
    }
    public function Risk(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'Risk.php';
    }
    public function Log(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        
        include admintem.'Log.php';
    }
    public function cron(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'cron.php';
    }
    public function Notice($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my'] ?:"list";
        $id = $get['id']??"";
        if($my == 'edit' && !empty($id)){
            $row = $this->db->noticerow($id);
        }
        include admintem.'Notice.php';
    }
    public function down($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my'] ?:"list";
        $id = $get['id']??"";
        if($my == 'edit' && !empty($id)){
            $row = $this->db->downrow($id);
        }
        include admintem.'down.php';
    }
    public function Work($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my'] ?:"list";
        $id = $get['id']??"";
        if($my == 'edit' && !empty($id)){
            $row = $this->db->workrow($id);
            $readonly = !empty($row['huifu']) ? 'readonly' : '';
            $class = !empty($row['huifu']) ? 'layui-textarea layui-form-danger' : 'layui-textarea';
        }
        include admintem.'Work.php';
    }
    public function qunemail($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my'] ?:"list";
        
        include admintem.'qunemail.php';
    }
    public function wxyunurl($get){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $my = $get['my']?:"list";
        $id = $this->input->id;
        if(!empty($id) && $my == 'edit'){
            $row = $this->db->wxyunurlrow($id);
        }
        include admintem.'wxyunurl.php';
    }
    public function account(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        include admintem.'account.php';
    }
    public function Update(){
        if($this->islogin_admin!='1')Commontc::falsetc("请先登录",rethreffun('/login'));
        $upjson = $this->CurlUrl->update_log($this);
        if($upjson['code'] == 1){
            $uplogtxt=nl2br(html_entity_decode($upjson['data']['sql_up_log']));
            $newup=$upjson['data']['sql_grade'];
        }
        $res = $this->CurlUrl->update_api_check($this);
        $res['msg'] = !empty($res['msg']) ? $res['msg'] : '啊哦，更新服务器开小差了，请刷新此页面。';
        $anniu = '暂无更新包';
        if($res['code'] == '1'){
            $anniu = !empty($res['anniu']) ? $res['anniu'] : '立即更新到最新版本';
        }
        $kedu = is_writable('./') ? '<font color="green">可用√</font>' : '<font color="black">不支持</font>';
        include admintem.'Update.php';
    }
}

?>